﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005A6 RID: 1446
	public class MPItemCtrl : MonoBehaviour
	{
		// Token: 0x1700046D RID: 1133
		// (set) Token: 0x060024BB RID: 9403 RVA: 0x000DA908 File Offset: 0x000D8B08
		public OCIItem ociItem
		{
			set
			{
				this.m_OCIItem = value;
				if (this.m_OCIItem != null)
				{
					this.UpdateInfo();
				}
			}
		}

		// Token: 0x1700046E RID: 1134
		// (get) Token: 0x060024BC RID: 9404 RVA: 0x000DA924 File Offset: 0x000D8B24
		// (set) Token: 0x060024BD RID: 9405 RVA: 0x000DA92C File Offset: 0x000D8B2C
		public bool active
		{
			get
			{
				return this.m_Active;
			}
			set
			{
				this.m_Active = value;
				if (this.m_Active)
				{
					base.gameObject.SetActive(this.m_OCIItem != null && (this.m_OCIItem.isChangeColor | this.m_OCIItem.isFK));
					this.animeControl.active = (this.m_OCIItem != null && this.m_OCIItem.isAnime);
				}
				else
				{
					if (!this.mpCharCtrl.active)
					{
						this.animeControl.active = false;
					}
					base.gameObject.SetActive(false);
					if (this.isColorFunc)
					{
						Singleton<Studio>.Instance.colorMenu.updateColorFunc = null;
					}
					this.isColorFunc = false;
				}
			}
		}

		// Token: 0x060024BE RID: 9406 RVA: 0x000DA9F4 File Offset: 0x000D8BF4
		private void UpdateInfo()
		{
			if (this.m_OCIItem == null)
			{
				return;
			}
			this.isUpdateInfo = true;
			if (this.objColor1.activeSelf != this.m_OCIItem.isChangeColor)
			{
				this.objColor1.SetActive(this.m_OCIItem.isChangeColor);
			}
			if (this.m_OCIItem.isChangeColor)
			{
				this.color1Info.imageColor.color = this.m_OCIItem.itemInfo.color.rgbDiffuse;
				this.color1Info.imageGloss.color = this.m_OCIItem.itemInfo.color.rgbSpecular;
				this.color1Info.sliderIntensity.value = this.m_OCIItem.itemInfo.color.specularIntensity;
				this.color1Info.inputFieldIntensity.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularIntensity);
				this.color1Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color.specularSharpness;
				this.color1Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularSharpness);
			}
			if (this.objColor2.activeSelf != this.m_OCIItem.isColor2)
			{
				this.objColor2.SetActive(this.m_OCIItem.isColor2);
			}
			if (this.m_OCIItem.isColor2)
			{
				this.color2Info.imageColor.color = this.m_OCIItem.itemInfo.color2.rgbDiffuse;
				this.color2Info.imageGloss.color = this.m_OCIItem.itemInfo.color2.rgbSpecular;
				this.color2Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color2.specularSharpness;
				this.color2Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color2.specularSharpness);
			}
			this.toggleFK.interactable = this.m_OCIItem.isFK;
			this.toggleFK.isOn = this.m_OCIItem.itemInfo.enableFK;
			this.animeControl.objectCtrlInfo = this.m_OCIItem;
			this.isUpdateInfo = false;
		}

		// Token: 0x060024BF RID: 9407 RVA: 0x000DAC64 File Offset: 0x000D8E64
		private void OnClickColor()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeColor);
			this.isColorFunc = true;
			Singleton<Studio>.Instance.colorMenu.SetColor(this.m_OCIItem.itemInfo.color.rgbaDiffuse, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x060024C0 RID: 9408 RVA: 0x000DACCC File Offset: 0x000D8ECC
		private void OnValueChangeColor(Color _color)
		{
			this.m_OCIItem.SetColor(_color);
			this.color1Info.imageColor.color = _color;
		}

		// Token: 0x060024C1 RID: 9409 RVA: 0x000DACEC File Offset: 0x000D8EEC
		private void OnClickColor2()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeColor2);
			this.isColorFunc = true;
			Singleton<Studio>.Instance.colorMenu.SetColor(this.m_OCIItem.itemInfo.color2.rgbaDiffuse, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x060024C2 RID: 9410 RVA: 0x000DAD54 File Offset: 0x000D8F54
		private void OnValueChangeColor2(Color _color)
		{
			this.m_OCIItem.SetColor2(_color);
			this.color2Info.imageColor.color = _color;
		}

		// Token: 0x060024C3 RID: 9411 RVA: 0x000DAD74 File Offset: 0x000D8F74
		private void OnClickGloss()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeGloss);
			this.isColorFunc = true;
			Singleton<Studio>.Instance.colorMenu.SetColor(this.m_OCIItem.itemInfo.color.rgbSpecular, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x060024C4 RID: 9412 RVA: 0x000DADDC File Offset: 0x000D8FDC
		private void OnValueChangeGloss(Color _color)
		{
			this.m_OCIItem.SetGloss(_color);
			this.color1Info.imageGloss.color = _color;
		}

		// Token: 0x060024C5 RID: 9413 RVA: 0x000DADFC File Offset: 0x000D8FFC
		private void OnValueChangeIntensity(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCIItem.SetIntensity(_value))
			{
				this.color1Info.inputFieldIntensity.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularIntensity);
			}
		}

		// Token: 0x060024C6 RID: 9414 RVA: 0x000DAE54 File Offset: 0x000D9054
		private void OnEndEditIntensity(string _text)
		{
			float value = Mathf.Max(0f, this.StringToFloat(_text));
			this.m_OCIItem.SetIntensity(Mathf.InverseLerp(0f, 100f, value));
			this.color1Info.sliderIntensity.value = this.m_OCIItem.itemInfo.color.specularIntensity;
			this.color1Info.inputFieldIntensity.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularIntensity);
		}

		// Token: 0x060024C7 RID: 9415 RVA: 0x000DAEE0 File Offset: 0x000D90E0
		private void OnClickIntensity()
		{
			this.m_OCIItem.itemInfo.color.specularIntensity = 0.4f;
			this.color1Info.sliderIntensity.value = this.m_OCIItem.itemInfo.color.specularIntensity;
			this.color1Info.inputFieldIntensity.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularIntensity);
		}

		// Token: 0x060024C8 RID: 9416 RVA: 0x000DAF58 File Offset: 0x000D9158
		private void OnValueChangeSharpness(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCIItem.SetSharpness(_value))
			{
				this.color1Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularSharpness);
			}
		}

		// Token: 0x060024C9 RID: 9417 RVA: 0x000DAFB0 File Offset: 0x000D91B0
		private void OnEndEditSharpness(string _text)
		{
			float value = Mathf.Max(0f, this.StringToFloat(_text));
			this.m_OCIItem.SetSharpness(Mathf.InverseLerp(0f, 100f, value));
			this.color1Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color.specularSharpness;
			this.color1Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularSharpness);
		}

		// Token: 0x060024CA RID: 9418 RVA: 0x000DB03C File Offset: 0x000D923C
		private void OnClickSharpness()
		{
			this.m_OCIItem.itemInfo.color.specularSharpness = 0.55f;
			this.color1Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color.specularSharpness;
			this.color1Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color.specularSharpness);
		}

		// Token: 0x060024CB RID: 9419 RVA: 0x000DB0B4 File Offset: 0x000D92B4
		private void OnClickGloss2()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeGloss2);
			this.isColorFunc = true;
			Singleton<Studio>.Instance.colorMenu.SetColor(this.m_OCIItem.itemInfo.color2.rgbSpecular, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x060024CC RID: 9420 RVA: 0x000DB11C File Offset: 0x000D931C
		private void OnValueChangeGloss2(Color _color)
		{
			this.m_OCIItem.SetGloss2(_color);
			this.color2Info.imageGloss.color = _color;
		}

		// Token: 0x060024CD RID: 9421 RVA: 0x000DB13C File Offset: 0x000D933C
		private void OnValueChangeSharpness2(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCIItem.SetSharpness2(_value))
			{
				this.color2Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color2.specularSharpness);
			}
		}

		// Token: 0x060024CE RID: 9422 RVA: 0x000DB194 File Offset: 0x000D9394
		private void OnEndEditSharpness2(string _text)
		{
			float value = Mathf.Max(0f, this.StringToFloat(_text));
			this.m_OCIItem.SetSharpness2(Mathf.InverseLerp(0f, 100f, value));
			this.color2Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color2.specularSharpness;
			this.color2Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color2.specularSharpness);
		}

		// Token: 0x060024CF RID: 9423 RVA: 0x000DB220 File Offset: 0x000D9420
		private void OnClickSharpness2()
		{
			this.m_OCIItem.itemInfo.color2.specularSharpness = 0.55f;
			this.color2Info.sliderSharpness.value = this.m_OCIItem.itemInfo.color2.specularSharpness;
			this.color2Info.inputFieldSharpness.text = this.ConvertString(this.m_OCIItem.itemInfo.color2.specularSharpness);
		}

		// Token: 0x060024D0 RID: 9424 RVA: 0x000DB298 File Offset: 0x000D9498
		private void OnValueChangedFK(bool _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			this.m_OCIItem.ActiveFK(_value);
		}

		// Token: 0x060024D1 RID: 9425 RVA: 0x000DB2B4 File Offset: 0x000D94B4
		private float StringToFloat(string _text)
		{
			float num = 0f;
			return (!float.TryParse(_text, out num)) ? 0f : num;
		}

		// Token: 0x060024D2 RID: 9426 RVA: 0x000DB2E0 File Offset: 0x000D94E0
		private string ConvertString(float _t)
		{
			return ((int)Mathf.Lerp(0f, 100f, _t)).ToString();
		}

		// Token: 0x060024D3 RID: 9427 RVA: 0x000DB30C File Offset: 0x000D950C
		private void Awake()
		{
			this.color1Info.buttonColor.onClick.AddListener(new UnityAction(this.OnClickColor));
			this.color1Info.buttonGloss.onClick.AddListener(new UnityAction(this.OnClickGloss));
			this.color1Info.sliderIntensity.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeIntensity));
			this.color1Info.inputFieldIntensity.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditIntensity));
			this.color1Info.buttonIntensityDefault.onClick.AddListener(new UnityAction(this.OnClickIntensity));
			this.color1Info.sliderSharpness.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeSharpness));
			this.color1Info.inputFieldSharpness.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditSharpness));
			this.color1Info.buttonSharpnessDefault.onClick.AddListener(new UnityAction(this.OnClickSharpness));
			this.color2Info.buttonColor.onClick.AddListener(new UnityAction(this.OnClickColor2));
			this.color2Info.buttonGloss.onClick.AddListener(new UnityAction(this.OnClickGloss2));
			this.color2Info.sliderSharpness.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeSharpness2));
			this.color2Info.inputFieldSharpness.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditSharpness2));
			this.color2Info.buttonSharpnessDefault.onClick.AddListener(new UnityAction(this.OnClickSharpness2));
			this.toggleFK.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangedFK));
			this.isUpdateInfo = false;
			this.m_Active = false;
			base.gameObject.SetActive(false);
		}

		// Token: 0x04002566 RID: 9574
		[SerializeField]
		private GameObject objColor1;

		// Token: 0x04002567 RID: 9575
		[SerializeField]
		private MPItemCtrl.ColorInfo color1Info;

		// Token: 0x04002568 RID: 9576
		[SerializeField]
		private GameObject objColor2;

		// Token: 0x04002569 RID: 9577
		[SerializeField]
		private MPItemCtrl.ColorInfo color2Info;

		// Token: 0x0400256A RID: 9578
		[SerializeField]
		private Toggle toggleFK;

		// Token: 0x0400256B RID: 9579
		[SerializeField]
		private AnimeControl animeControl;

		// Token: 0x0400256C RID: 9580
		[SerializeField]
		private MPCharCtrl mpCharCtrl;

		// Token: 0x0400256D RID: 9581
		private OCIItem m_OCIItem;

		// Token: 0x0400256E RID: 9582
		private bool m_Active;

		// Token: 0x0400256F RID: 9583
		private bool isUpdateInfo;

		// Token: 0x04002570 RID: 9584
		private bool isColorFunc;

		// Token: 0x020005A7 RID: 1447
		[Serializable]
		private class ColorInfo
		{
			// Token: 0x04002571 RID: 9585
			public Image imageColor;

			// Token: 0x04002572 RID: 9586
			public Button buttonColor;

			// Token: 0x04002573 RID: 9587
			public Image imageGloss;

			// Token: 0x04002574 RID: 9588
			public Button buttonGloss;

			// Token: 0x04002575 RID: 9589
			public Slider sliderIntensity;

			// Token: 0x04002576 RID: 9590
			public InputField inputFieldIntensity;

			// Token: 0x04002577 RID: 9591
			public Button buttonIntensityDefault;

			// Token: 0x04002578 RID: 9592
			public Slider sliderSharpness;

			// Token: 0x04002579 RID: 9593
			public InputField inputFieldSharpness;

			// Token: 0x0400257A RID: 9594
			public Button buttonSharpnessDefault;
		}
	}
}
